package com.proxy.custom.demo;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * DesignPatterns
 *
 * @Title: com.proxy.jdkProxy
 * @Date: 2021/1/10 0010 9:42
 * @Author: wfg
 * @Description:
 * @Version:
 */
public class MyInvocationHandler implements InvocationHandler {
    private Object target;

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    public Object getInstance(){
        /**
         * ClassLoader loader,
         * Class<?>[] interfaces,
         * InvocationHandler h
         */
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println(proxy.getClass().getSimpleName());
        System.out.println(method.getName());
        System.out.println(args);
        Object invoke = method.invoke(target, args);
        return invoke;
    }
}
